import tkinter as tk
import random
import threading
import time
import sys

# ------------------------------------------------------------------
# 1. 全局生死开关
# ------------------------------------------------------------------
running = True

# ------------------------------------------------------------------
# 2. 情话池：想加多少加多少
# ------------------------------------------------------------------
LOVE_WORDS = [
    "我想你了！",
    "今天也很喜欢你。",
    "见你就开心。",
    "你是人间理想。",
    "月亮奔向你。",
    "全世界都可以是你的。",
    "偷偷喜欢你。",
    "余生很长，想和你没完没了。",
    "你是我藏在微风里的喜欢。",
    "把星星摘给你，好不好？",
    "想做你一生的主题曲。",
    "喜欢你。",
    "想撞进你怀里。",
    "我想和你有以后。",
    "你是我所有的不动声色里最澎湃的一笔。",
    "第一眼我就喜欢你。",
    "环游遍了整个星系，找不到比你更亮的星。",
    "你是我日复一日的梦想。",
    "我想和你一屋两人三餐四季。",
    "我希望压得我喘不过气的不是生活，是你。",
]

# ------------------------------------------------------------------
# 3. 随机颜色辅助函数（柔和 pastel 系，防止太刺眼）
# ------------------------------------------------------------------
def random_bg_color():
    """返回一个柔和的随机背景色（RGB 十六进制）"""
    r = lambda: random.randint(160, 255)
    return f"#{r():02X}{r():02X}{r():02X}"

# ------------------------------------------------------------------
# 4. 单窗口线程函数
# ------------------------------------------------------------------
def dow():
    window = tk.Tk()
    width = window.winfo_screenwidth()
    height = window.winfo_screenheight()

    # 随机出生坐标
    x = random.randrange(0, width - 220)
    y = random.randrange(0, height - 50)

    window.title("亲爱的")
    window.geometry(f"220x50+{x}+{y}")
    window.attributes("-topmost", True)
    window.configure(bg=random_bg_color())   # 随机背景

    # 随机挑一句情话
    sentence = random.choice(LOVE_WORDS)

    tk.Label(window,
             text=sentence,
             fg="#4a148c",                # 字体颜色：深紫，好看
             bg=window["bg"],             # 与窗口背景一致
             font=("楷体", 18),
             width=25, height=4).pack()

    # 心跳：检测全局开关
    def heartbeat():
        if not running:
            window.destroy()
        else:
            window.after(50, heartbeat)

    heartbeat()
    window.mainloop()

# ------------------------------------------------------------------
# 5. 8 秒后集体自爆
# ------------------------------------------------------------------
def killer():
    global running
    time.sleep(8)
    running = False        # 通知所有窗口
    time.sleep(0.5)
    sys.exit(0)            # 强制结束进程

# ------------------------------------------------------------------
# 6. 启动定时杀手（守护线程）
# ------------------------------------------------------------------
threading.Thread(target=killer, daemon=True).start()

# ------------------------------------------------------------------
# 7. 批量创建 200 个窗口线程
# ------------------------------------------------------------------
threads = []
for _ in range(200):
    t = threading.Thread(target=dow)
    threads.append(t)
    time.sleep(0.01)   # 稍微错开，降低瞬间压力
    t.start()